package com.serli.sample.data.runner.service;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.serli.sample.data.runner.domain.Trip;

public class TripService extends AbstractService {

	public TripService(EntityManager manager) {
		super(manager);
	}
	
	@SuppressWarnings("unchecked")
	public List<Trip> getAllOrderByName() {
		List<Trip> result = new ArrayList<Trip>();
		result = manager.createNamedQuery(Trip.QUERY_FIND_ALL_ORDER_BY_NAME).getResultList();
		return result;
	}

	@SuppressWarnings("unchecked")
	public Trip getByName(String name) {
		Query query = manager.createNamedQuery(Trip.QUERY_FIND_BY_NAME);
		query.setParameter(Trip.PARAMETER_NAME, name);
		List<Trip> courses = query.getResultList();

		return (courses != null && courses.size() > 0)? courses.get(0) : null;
	}

}
